$(function () {
    getAboutMe();
    $("#submitbtn").click(function () {
        var oldpwd=$("#oldPassword").val()
        var newpwd=$("#newpassword").val();
        var confirmpwd=$("#confirmnewpassword").val();
        if(oldpwd==''){
            swal("请输入旧密码!");
            return;
        }
        if(newpwd==''){
            swal("请输入新密码!");
            return;
        }
        if(newpwd!=confirmpwd){
            swal("两次输入密码不一致!");
            return;
        }
        $.post({
            url:  baseurl+api.user.password,
            xhrFields: {
                withCredentials: true
            },
            data: $("#pwd-form").serialize(),
            success: function (res) {
                swal(res.message);
                if(res.code=="200"){   //密码修改成功，退出到登录页面
                    setTimeout(function () {
                        window.location.href="/logout";
                    },1000);
                }
            }
        })
    })
})
function save() {
    var about = $("#my-text").val();
    $.post({
        url: baseurl+api.about.set,
        data: {about:about},
        xhrFields: {
            withCredentials: true
        },
        success: function (res) {
            swal(res.message);
            setTimeout(function () {
                window.location.reload();
            },1000);
        }
    })
}

function getAboutMe() {
    $.post({
        url: baseurl+api.about.get,
        xhrFields: {
            withCredentials: true
        },
        success: function (res) {
            $("#my-text").val(res.data);
        }
    })
}